<?php
require_once("model/B_requestBean.class.php");
include_once("controller/Paging.class.php");
include_once("includes/util.php");
/**
 * dashboard class. This is a class used to process all
 * logic of dashboard tab in admin page.
 */
class register 
{
	var $db;
 	var $smarty;
 	
    function register($db, $smarty)
	{
		//store pointer to db onject
		$this->db = $db;
		$this->smarty = $smarty;
	}
	
	/**
	 * This function will be call be index.php base on mod specified by GET param
	 */
	function process()
	{
		if(isset($_POST['act'])){
			$act = $_POST['act'];
			if($act == "delregister"){
				$this->delRegister();	
			}
		}	
		$request = new B_requestBean($db, $smarty);
		$countregister=$request->countRegister($this->db);
 			$register['data']=$request->getRegisterSharePageAdmin($this->db,MAX_DEMO_NEWS_ADMIN,'list');
			$link = "?mod=".$_GET['mod'];
			$result = Paging::do_paging($countregister,$register, MAX_DEMO_NEWS_ADMIN, $link,"list");
		$this->smarty->assign("REGISTER", $result);
		$this->smarty->display('register.tpl');
	}
	
	/**
	 * Process Ajax call for delete a category
	 */
	function delRegister()
	{
		$request = new B_requestBean($db, $smarty);
		$arr = array("code" => -1, "message" => _("Invalid Arguments."));
		if(isset( $_POST['id'])){
			$res = $request->deleteRegister($this->db, $_POST['id']);
			if($res)
			{
				$arr['code'] = 0;
				$arr['message'] = sprintf(_("Pre-Register with Id %s has been deleted."),
										"<b>". $_POST['id'] . "</b>");
				
			}
		}
		echo array2json($arr);
		
		return;	//we use ajax delete product, so no need to show rest of page here
	}
}
?>